#include <iostream>
using std::cout;
using std::endl;

class Point;

class Complex{
public:
    Complex(double real,double image)
    : _real(real)
    , _image(image)
    {
        cout << "Complex(double,double)" << endl;
    }

    Complex(const Point & pt);

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }
private:
    double _real;
    double _image;
};

class Point{
public:
    /* explicit */
    Point(int x,int y = 10)
    : _ix(x)
    , _iy(y)
    {}

    operator int(){
        return _ix + _iy;
    }

    //operator Complex(){
    //    return Complex(_ix,_iy);
    //}
    friend class Complex; 
private:
    int _ix;
    int _iy;
};

Complex::Complex(const Point & pt)
: _real(pt._ix)
, _image(pt._iy)
{
    cout << "Complex(const Point &)" << endl;
}

void test0(){
    Point pt(1);
    //隐式转换，借助构造函数完成
    //编译器会看能否只用一个int数据就构造一个Point对象，
    //若可以就发生隐式转换
    Point pt2 = 2;

    //Point类对象转换成了一个int变量
    int z = pt2;
    cout << z << endl;

    Complex cx = pt;
    cx.print();

}

int main(void){
    test0();
    return 0;
}
